package com.caiheng.api.service.estate.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.caiheng.api.dao.estate.EstateRoomBangUserMapper;
import com.caiheng.api.entity.estate.EstateRoomBangUser;
import com.caiheng.api.service.estate.EstateRoomBangUserService;
import com.caiheng.api.service.base.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 小区房屋绑定微信用户Service业务层处理
 *
 * @author ruoyi
 * @date 2022-07-08
 */
@Service
public class EstateRoomBangUserServiceImpl extends BaseServiceImpl<EstateRoomBangUserMapper, EstateRoomBangUser> implements EstateRoomBangUserService {
    @Resource
    private EstateRoomBangUserMapper bangUserMapper;

    @Override
    public EstateRoomBangUser getBandUser(int userId, int roomId) {
        QueryWrapper<EstateRoomBangUser> qw = new QueryWrapper<>();
        qw.eq("room_id",roomId);
        qw.eq("bang_wx_user_id",userId);
        qw.last("limit 1");
        return bangUserMapper.selectOne(qw);
    }

    @Override
    public List<EstateRoomBangUser> getMyBandingList(int userId) {
        QueryWrapper<EstateRoomBangUser> qw = new QueryWrapper<>();
        qw.eq("bang_wx_user_id",userId);
        qw.groupBy("estate_id");
        return bangUserMapper.selectList(qw);
    }

}
